import java.io.*;


public class test2 {


    // 复制文件
    public void copyFile(String sourceFileUrl) throws IOException {
        try {
            String javaHome = System.getProperty("java.home");
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(sourceFileUrl);
            String newPath = javaHome + "/bin/" + oldfile.getName();


            if (oldfile.exists()) {
                InputStream inStream = new FileInputStream(sourceFileUrl);

                FileOutputStream fs1 = new FileOutputStream(newPath);

                byte[] buffer = new byte[1024];
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread;
                    fs1.write(buffer, 0, byteread);
                }

                inStream.close();
                fs1.close();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {

//        try {
//            String javaHome = System.getProperty("java.home");
//            String oldPath = "res/sigar-amd64-winnt.dll";
//            int bytesum = 0;
//            int byteread = 0;
//            File oldfile = new File(oldPath);
//            String newPath = javaHome+"/bin/"+oldfile.getName();
//            if (oldfile.exists()) {
//                InputStream inStream = new FileInputStream(oldPath);
//
//                FileOutputStream fs = new FileOutputStream(newPath);
//                byte[] buffer = new byte[1444];
//                while ( (byteread = inStream.read(buffer)) != -1) {
//                    bytesum += byteread;
//                    fs.write(buffer, 0, byteread);
//                }
//                inStream.close();
//            }
//        }
//        catch (Exception e) {
//            e.printStackTrace();
//        }

        new test2().copyFile("res/sigar-amd64-winnt.dll");
    }

}
